package com.example.controller.buyer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.dto.EvaluationDTO;
import com.example.service.OrderEvaluationService;
import com.example.vo.LoginUser;
import com.example.vo.MyEvaluationVO;
import com.example.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author circle48
 */
@RestController
@Api(tags = "买家端,会员商品评价接口")
@RequestMapping("/buyer/evaluation")
public class OrderEvaluationBuyerController {

    /**
     * 会员商品评价
     */
    @Autowired
    private OrderEvaluationService orderEvaluationService;

    @ApiOperation(value = "查看当前会员评价列表")
    @GetMapping
    public Result<IPage<MyEvaluationVO>> queryMineEvaluation(Integer pageNum,
                                                             Integer pageSize,
                                                             @RequestParam(required = false) String evaluationStatus) {
        //设置当前登录会员
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        Long id = loginUser.getUser().getId();
        return orderEvaluationService.queryMineEvaluation(pageNum,pageSize,id,evaluationStatus);
    }


    @ApiOperation(value = "新增商品评价")
    @PostMapping("/add")
    public Result addEvaluation(@RequestBody EvaluationDTO dto) {
        //设置当前登录会员
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        Long id = loginUser.getUser().getId();

        return orderEvaluationService.addEvaluation(dto);
    }
}
